package net.my.msn.dao;

import java.io.Serializable;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

public abstract class JpaImplTemplateDAO<T, ID extends Serializable> implements
		TemplateDAO<T, ID> {

	public JpaImplTemplateDAO(Class<T> type) {
		this.type = type;
	}

	public void create(T obj) {
		em.persist(obj);
	}

	public T read(ID id) {
		return (T) em.find(type, id);
	}

	public T update(T obj) {
		return em.merge(obj);
	}

	public void delete(T obj) {
		em.remove(obj);
	}

	@PersistenceContext
	public EntityManager em;
	protected Class<T> type;

}
